package com.projectzqjz.parttimework.ui.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.projectzqjz.parttimework.App;
import com.projectzqjz.parttimework.R;
import com.projectzqjz.parttimework.adapter.PartWorkAdapter;
import com.projectzqjz.parttimework.base.BaseActivity;
import com.projectzqjz.parttimework.entity.JobExpEntity;
import com.projectzqjz.parttimework.entity.PartBaseEntity;
import com.projectzqjz.parttimework.entity.PartResumeEntity;
import com.projectzqjz.parttimework.entity.PartWorkEntity;
import com.projectzqjz.parttimework.net.MyCallback;
import com.projectzqjz.parttimework.net.Task;
import com.projectzqjz.parttimework.utils.AppConfig;
import com.projectzqjz.parttimework.utils.NewsToastUtils;
import com.projectzqjz.parttimework.utils.SPUtils;
import com.projectzqjz.parttimework.utils.ScreenUtil;
import com.projectzqjz.parttimework.utils.TitleBuilder;
import com.projectzqjz.parttimework.widget.CenterDialog;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
import retrofit2.Response;

import static com.projectzqjz.parttimework.base.Constant.ADDRESS;
import static com.projectzqjz.parttimework.base.Constant.ADD_WORK;
import static com.projectzqjz.parttimework.base.Constant.BUSINESS;
import static com.projectzqjz.parttimework.base.Constant.CHANGEINFO;
import static com.projectzqjz.parttimework.base.Constant.DELETE;
import static com.projectzqjz.parttimework.base.Constant.EDITOR_WORK;
import static com.projectzqjz.parttimework.base.Constant.EMAIL;
import static com.projectzqjz.parttimework.base.Constant.PHONE;
import static com.projectzqjz.parttimework.base.Constant.SAVE;
import static com.projectzqjz.parttimework.base.Constant.SCHOOL;
import static com.projectzqjz.parttimework.base.Constant.ZY;

public class PartMyDiaryActivity extends BaseActivity {
    @BindView(R.id.iv_title_right)
    ImageView iv_title_right;

    @BindView(R.id.tv_name)
    TextView tvName;

    @BindView(R.id.tv_detail)
    TextView tvDetail;

    @BindView(R.id.sex_1)
    ImageView sex1;
    @BindView(R.id.sex_3)
    ImageView sex3;
    @BindView(R.id.profession_1)
    ImageView profession1;
    @BindView(R.id.profession_3)
    ImageView profession3;


    @BindView(R.id.state_1)
    ImageView state1;
    @BindView(R.id.state_3)
    ImageView state3;

    @BindView(R.id.rel_add_work)
    LinearLayout rel_add_work;

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    @BindView(R.id.tv_start)
    TextView tv_start;//入学时间
    @BindView(R.id.tv_end)
    TextView tv_end;//毕业时间


    @BindView(R.id.tv_education)
    TextView tv_education;//学历
    @BindView(R.id.tv_school)
    TextView tv_school;//学校名称
    @BindView(R.id.tv_zy)
    TextView tv_zy;//专业

    @BindView(R.id.tv_business)
    TextView tv_business;//商务合作
    @BindView(R.id.tv_address)
    TextView tv_address;//现居住地
    @BindView(R.id.tv_phone)
    TextView tv_phone;//手机号
    @BindView(R.id.tv_email)
    TextView tv_email;//邮箱
    @BindView(R.id.tv_age)
    TextView tv_age;
    @BindView(R.id.iv_head)
    CircleImageView iv_head;

    @BindView(R.id.ed_mine)
    EditText ed_mine;
    private OptionsPickerView educationPickerView;//选择器
    private OptionsPickerView agePickerView;//选择器
    private int sex = 0;//0 表示男  1 表示女
    private int profession = 0;//0表示学生  1 表示非学生
    private int state = 0;//0表示在职  1 表示离职
    private int type = -1;
    private PartWorkAdapter partWorkAdapter = null;
    private List<PartWorkEntity> partWorkEntities = new ArrayList<>();//工作经历
    private TimePickerView pvCustomLunar;
    private String name = "";
    private String head = "";
    private String address = "";
    private String mobile = "";

    private String email = "";
    private String school = "";
    private String zyName = "";

    private boolean isHave = false;
    private String avatar;//头像

    @OnClick({R.id.rel_education, R.id.sex_1, R.id.sex_2, R.id.sex_3, R.id.sex_4,
            R.id.profession_1, R.id.profession_2, R.id.profession_3, R.id.profession_4
            , R.id.state_1, R.id.state_2, R.id.state_3, R.id.state_4, R.id.rel_add_work
            , R.id.rel_start_education, R.id.rel_end_education, R.id.rel_cooperation
            , R.id.rel_address, R.id.rel_phone, R.id.rel_email, R.id.rel_school
            , R.id.rel_zy, R.id.iv_mineInfo, R.id.iv_title_right, R.id.rel_age, R.id.iv_save
    })
    public void onViewClicked(View view) {
        if (ScreenUtil.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.rel_education: //选择学历
                selectEducation();
                break;
            case R.id.sex_1:
            case R.id.sex_2:
                sex1.setImageResource(R.drawable.icon_selected);
                sex3.setImageResource(R.drawable.icon_unselected);
                sex = 0;
                break;
            case R.id.sex_3:
            case R.id.sex_4:
                sex3.setImageResource(R.drawable.icon_selected);
                sex1.setImageResource(R.drawable.icon_unselected);
                sex = 1;
                break;
            case R.id.profession_1:
            case R.id.profession_2:
                profession1.setImageResource(R.drawable.icon_selected);
                profession3.setImageResource(R.drawable.icon_unselected);
                profession = 0;
                break;
            case R.id.profession_3:
            case R.id.profession_4:
                profession3.setImageResource(R.drawable.icon_selected);
                profession1.setImageResource(R.drawable.icon_unselected);
                profession = 1;
                break;
            case R.id.state_1:
            case R.id.state_2:
                state1.setImageResource(R.drawable.icon_selected);
                state3.setImageResource(R.drawable.icon_unselected);
                state = 0;
                break;
            case R.id.state_3:
            case R.id.state_4:
                state3.setImageResource(R.drawable.icon_selected);
                state1.setImageResource(R.drawable.icon_unselected);
                state = 1;
                break;
            case R.id.rel_add_work://添加工作经历
                startActivityForResult(new Intent(this, PartWorkActivity.class).putExtra("state", "add")
                        , ADD_WORK);
                break;
            case R.id.rel_start_education://入学时间
                type = 0;
                pvCustomLunar.show();
                break;
            case R.id.rel_end_education://毕业时间
                type = 1;
                pvCustomLunar.show();
                break;
            case R.id.rel_cooperation://商务合作
                startActivityForResult(new Intent(this, PartEditorActivity.class)
                        .putExtra("title", "商务合作"), BUSINESS);
                break;
            case R.id.rel_address://现居住地
                startActivityForResult(new Intent(this, PartAddressActivity.class)
                        .putExtra("title", "现居住地"), ADDRESS);
                break;
            case R.id.rel_phone://手机号码
                startActivityForResult(new Intent(this, PartEditorActivity.class)
                        .putExtra("title", "手机号码"), PHONE);
                break;
            case R.id.rel_email://邮箱
                startActivityForResult(new Intent(this, PartEditorActivity.class)
                        .putExtra("title", "邮箱"), EMAIL);
                break;
            case R.id.rel_school://学校名称
                startActivityForResult(new Intent(this, PartEditorActivity.class)
                        .putExtra("title", "学校名称"), SCHOOL);
                break;
            case R.id.rel_zy://专业
                startActivityForResult(new Intent(this, PartEditorActivity.class)
                        .putExtra("title", "专业"), ZY);
                break;
            case R.id.iv_mineInfo://修改个人中心
                    startActivityForResult(new Intent(this, PartMineInfoActivity.class)
                            .putExtra("head",avatar).putExtra("name", tvName.getText().toString()), CHANGEINFO);

                break;
            case R.id.iv_title_right://查看简历详情
                if (isHave) {
                    startActivity(new Intent(this, PartWebCommonActivity.class)
                            .putExtra("url", AppConfig.getInstance(App.getContext()).get("pesume_preview"))
                            .putExtra("title", "简历预览"));
                } else {
                    NewsToastUtils.showToast(App.getContext(), "你还没有简历，请完善简历！");
                }

                break;
            case R.id.rel_age://年龄
                selectage();
                break;
            case R.id.iv_save://保存简历
                if (tvName.getText().toString().equals("")) {
                    NewsToastUtils.showToast(App.getContext(), "姓名不能为空");
                } else if (tv_age.getText().toString().equals("")) {
                    NewsToastUtils.showToast(App.getContext(), "年龄不能为空");
                } else if (tv_address.getText().toString().equals("")) {
                    NewsToastUtils.showToast(App.getContext(), "地址不能为空");
                } else if (tv_phone.getText().toString().equals("")) {
                    NewsToastUtils.showToast(App.getContext(), "手机号不能为空");
                } else if (tv_email.getText().toString().equals("")) {
                    NewsToastUtils.showToast(App.getContext(), "邮箱不能为空");
                } else {
                    if (!tv_start.getText().toString().equals("") && !tv_end.getText().toString().equals("")) {
                        if (checkTime(tv_start.getText().toString(), tv_end.getText().toString())) {
                            addResume();
                        }
                    } else {
                        addResume();
                    }

                }

                break;
        }
    }

    //检测时间大小
    private boolean checkTime(String time1, String time2) {
        String[] start = time1.split("\\.");
        String[] end = time2.split("\\.");
        if (Integer.parseInt(start[0]) < Integer.parseInt(end[0])) {
            return true;
        } else if (Integer.parseInt(start[0]) == Integer.parseInt(end[0])) {
            if (Integer.parseInt(start[1]) <= Integer.parseInt(end[1])) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    //弹出时间滑动选择
    @SuppressLint("SimpleDateFormat")
    private String getTime(Date date) {//可根据需要自行截取数据显示
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        String str = format.format(date);
        return str.split("-")[0] + "." + str.split("-")[1];
    }

    @SuppressLint("WrongConstant")
    private void initLunarPicker() {
        Calendar selectedDate = Calendar.getInstance();//系统当前时间
        Calendar startDate = Calendar.getInstance();
        startDate.set(1950, 0, 1);
        Calendar endDate = Calendar.getInstance();
        endDate.set(2019, 11, 1);
        //时间选择器 ，自定义布局
        pvCustomLunar = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                switch (type) {
                    case 0:
                        tv_start.setText(getTime(date));
                        break;
                    case 1:
                        tv_end.setText(getTime(date));
                        break;
                }
            }
        })
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .setLayoutRes(R.layout.pickerview_custom_lunar, new CustomListener() {

                    @Override
                    public void customLayout(final View v) {
                        TextView tvSubmit = (TextView) v.findViewById(R.id.tv_submit);//确定
                        TextView tvCanncel = (TextView) v.findViewById(R.id.tv_cancel);//取消
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                pvCustomLunar.returnData();
                                pvCustomLunar.dismiss();
                            }
                        });
                        tvCanncel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                pvCustomLunar.returnData();
                                pvCustomLunar.dismiss();
                            }
                        });

                    }
                })
                .setType(new boolean[]{true, true, false, false, false, false})
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setDividerColor(getResources().getColor(R.color.colorEEE))
                .build();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            assert data != null;
            switch (requestCode) {
                case ADD_WORK://添加工作经历

                    Bundle bundle = data.getBundleExtra("workModel");
                    assert bundle != null;
                    PartWorkEntity partWorkEntity = new PartWorkEntity();
                    partWorkEntity.setCompany_name(bundle.getString("company_name"));
                    partWorkEntity.setContent(bundle.getString("content"));
                    partWorkEntity.setTime(bundle.getString("time"));
                    partWorkEntity.setJob(bundle.getString("job"));
                    partWorkEntities.add(partWorkEntity);
                    if (partWorkEntities.size() > 0) {
                        rel_add_work.setVisibility(View.GONE);
                        recyclerView.setVisibility(View.VISIBLE);
                    } else {
                        rel_add_work.setVisibility(View.VISIBLE);
                        recyclerView.setVisibility(View.GONE);
                    }
                    partWorkAdapter.notifyDataSetChanged();
                    break;
                case EDITOR_WORK://编辑简历
                    Bundle bundle_1 = data.getBundleExtra("workModel");
                    assert bundle_1 != null;
                    String position = bundle_1.getString("position");

                    String save_delete = bundle_1.getString("SAVE_DELETE");
                    assert save_delete != null;
                    if (save_delete.equals(SAVE + "")) {
                        assert position != null;
                        PartWorkEntity partWorkEntity_1 = partWorkEntities.get(Integer.parseInt(position));
                        partWorkEntity_1.setCompany_name(bundle_1.getString("company_name"));
                        partWorkEntity_1.setContent(bundle_1.getString("content"));
                        partWorkEntity_1.setTime(bundle_1.getString("time"));
                        partWorkEntity_1.setJob(bundle_1.getString("job"));
                        if (partWorkEntities.size() > 0) {
                            rel_add_work.setVisibility(View.GONE);
                            recyclerView.setVisibility(View.VISIBLE);
                        } else {
                            rel_add_work.setVisibility(View.VISIBLE);
                            recyclerView.setVisibility(View.GONE);
                        }
                        partWorkAdapter.notifyDataSetChanged();
                    } else if (save_delete.equals(DELETE + "")) {
                        int delete = Integer.parseInt(position);
                        partWorkEntities.remove(delete);
                        if (partWorkEntities.size() > 0) {
                            rel_add_work.setVisibility(View.GONE);
                            recyclerView.setVisibility(View.VISIBLE);
                        } else {
                            rel_add_work.setVisibility(View.VISIBLE);
                            recyclerView.setVisibility(View.GONE);
                        }
                        partWorkAdapter.notifyDataSetChanged();
                    }

                    break;
                case BUSINESS://商务合作
                    tv_business.setText(data.getStringExtra("name"));
                    break;
                case ADDRESS://现居住地
                    address = data.getStringExtra("name");
                    tv_address.setText(address);
                    break;
                case PHONE://手机号码
                    mobile = data.getStringExtra("name");
                    tv_phone.setText(mobile);
                    break;
                case EMAIL://邮箱
                    email = data.getStringExtra("name");
                    tv_email.setText(email);
                    break;
                case SCHOOL://学校名称
                    school = data.getStringExtra("name");
                    tv_school.setText(school);
                    break;
                case ZY://专业
                    zyName = data.getStringExtra("name");
                    tv_zy.setText(zyName);
                    break;
                case CHANGEINFO://修改个人信息
                    name = data.getStringExtra("name");
                    head = data.getStringExtra("head");
                    if (!"".equals(head))
                        Picasso.with(this).load(head).into(iv_head);
                    tvName.setText(name);
                    break;
            }
        }

    }

    //弹出学历滑动选择
    private void selectEducation() {
        List<String> educations = new ArrayList<>();
        educations.add("初中以下");
        educations.add("初中");
        educations.add("高中");
        educations.add("大专");
        educations.add("本科");
        educations.add("硕士");
        educations.add("硕士及以上");
        educationPickerView = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {
//                //返回的分别是三个级别的选中位置
                String tx = educations.get(options1);
                tv_education.setText(tx);
            }
        })
                .setLayoutRes(R.layout.item_sliding_choice, new CustomListener() {
                    @Override
                    public void customLayout(View v) {
                        TextView tvSubmit = (TextView) v.findViewById(R.id.tv_submit);//确定
                        TextView tvCanncel = (TextView) v.findViewById(R.id.tv_cancel);//取消
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                educationPickerView.returnData();
                                educationPickerView.dismiss();
                            }
                        });
                        tvCanncel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                educationPickerView.returnData();
                                educationPickerView.dismiss();
                            }
                        });

                    }
                })
                .setContentTextSize(20)//滚轮文字大小
                .setTextColorCenter(getResources().getColor(R.color.color333))//设置选中文本的颜色值
                .setLineSpacingMultiplier(1.8f)//行间距
                .setDividerColor(getResources().getColor(R.color.color999))//设置分割线的颜色
                .setSelectOptions(0)//设置选择的值
                .build();
        educationPickerView.setPicker(educations);//添加数据
        educationPickerView.show();
    }

    //弹出学历滑动选择
    private void selectage() {
        List<String> educations = new ArrayList<>();
        educations.add("0");
        educations.add("1");
        educations.add("2");
        educations.add("3");
        educations.add("4");
        educations.add("5");
        educations.add("6");
        educations.add("7");
        educations.add("8");
        educations.add("9");
        educations.add("10");
        educations.add("11");
        educations.add("12");
        educations.add("13");
        educations.add("14");
        educations.add("15");
        educations.add("16");
        educations.add("17");
        educations.add("18");
        educations.add("19");
        educations.add("20");
        educations.add("21");
        educations.add("22");
        educations.add("23");
        educations.add("24");
        educations.add("25");
        educations.add("26");
        educations.add("27");
        educations.add("28");
        educations.add("29");
        educations.add("30");
        educations.add("31");
        educations.add("32");
        educations.add("33");
        educations.add("34");

        educations.add("35");
        educations.add("36");
        educations.add("37");
        educations.add("38");
        educations.add("39");
        educations.add("40");
        educations.add("41");
        educations.add("42");
        educations.add("43");
        educations.add("44");
        educations.add("45");
        educations.add("46");
        educations.add("47");
        educations.add("48");
        educations.add("49");
        educations.add("50");
        educations.add("51");
        educations.add("52");
        educations.add("53");
        educations.add("54");
        educations.add("55");
        educations.add("56");
        educations.add("57");
        educations.add("58");
        educations.add("59");
        educations.add("60");
        educations.add("61");
        educations.add("62");
        educations.add("63");
        educations.add("64");
        educations.add("65");
        agePickerView = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {
//                //返回的分别是三个级别的选中位置
                String tx = educations.get(options1);
                tv_age.setText(tx);
            }
        })
                .setLayoutRes(R.layout.item_sliding_choice, new CustomListener() {
                    @Override
                    public void customLayout(View v) {
                        TextView tvSubmit = (TextView) v.findViewById(R.id.tv_submit);//确定
                        TextView tvCanncel = (TextView) v.findViewById(R.id.tv_cancel);//取消
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                agePickerView.returnData();
                                agePickerView.dismiss();
                            }
                        });
                        tvCanncel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                agePickerView.returnData();
                                agePickerView.dismiss();
                            }
                        });

                    }
                })
                .setContentTextSize(20)//滚轮文字大小
                .setTextColorCenter(getResources().getColor(R.color.color333))//设置选中文本的颜色值
                .setLineSpacingMultiplier(1.8f)//行间距
                .setDividerColor(getResources().getColor(R.color.color999))//设置分割线的颜色
                .setSelectOptions(0)//设置选择的值
                .build();
        agePickerView.setPicker(educations);//添加数据
        agePickerView.show();
    }

    @Override
    public void setListen() {

    }

    @Override
    public void setTitleBarColor() {

    }

    @Override
    public int intiLayout() {
        return R.layout.activity_part_mydiary;
    }

    @Override
    protected boolean isStatusBarBlack() {
        return true;
    }

    @Override
    public void initView() {
        iv_title_right.setImageResource(R.drawable.icon_preview);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        if (partWorkAdapter == null) {
            partWorkAdapter = new PartWorkAdapter(PartMyDiaryActivity.this, partWorkEntities);
        }
        recyclerView.setHasFixedSize(true);
        recyclerView.setNestedScrollingEnabled(false);
        // 第一种，直接取消动画
        RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
        if (animator instanceof SimpleItemAnimator) {
            ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
        }
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(partWorkAdapter);
        initLunarPicker();
        new TitleBuilder(this).setTitleText("我的简历")
                .setLeftIcoListening(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });

    }

    @Override
    public void initData() {
        getResume();
    }

    //获取简历
    private void getResume() {
        Dialog dialog = new CenterDialog(R.layout.loading_layout, PartMyDiaryActivity.this).showLoad("正在拉取简历...");
        Task.getApiService().getResume().enqueue(new MyCallback<PartBaseEntity>(PartMyDiaryActivity.this) {
            @Override
            protected void onSuccess(Response<PartBaseEntity> response) {
                dialog.dismiss();
                assert response.body() != null;
                if (response.body().getData().equals("")) {
                    isHave = false;
                    NewsToastUtils.showToast(App.getContext(), "请填写简历！");
                } else {
                    isHave = true;
                    String jsonStr = JSONObject.toJSONString(response.body().getData()) + "";
                    JSONObject jsonObject = JSONObject.parseObject(jsonStr);
                    avatar = jsonObject.getString("avatar") + "";
                    if (avatar.equals("")) {
                        Picasso.with(PartMyDiaryActivity.this).load(R.mipmap.head).into(iv_head);
                    } else {
                        Picasso.with(PartMyDiaryActivity.this).load(avatar).into(iv_head);
                    }

                    String sex11 = jsonObject.getInteger("sex") + "";
                    if (sex11.equals("0")) {
                        sex1.setImageResource(R.drawable.icon_selected);
                        sex3.setImageResource(R.drawable.icon_unselected);
                        sex = 0;
                    } else {
                        sex3.setImageResource(R.drawable.icon_selected);
                        sex1.setImageResource(R.drawable.icon_unselected);
                        sex = 1;
                    }

                    String age = jsonObject.getInteger("age") + "";
                    tv_age.setText(age);
                    String job = jsonObject.getString("job");

                    if (job.equals("0")) {
                        profession1.setImageResource(R.drawable.icon_selected);
                        profession3.setImageResource(R.drawable.icon_unselected);
                        profession = 0;
                    } else {
                        profession3.setImageResource(R.drawable.icon_selected);
                        profession1.setImageResource(R.drawable.icon_unselected);
                        profession = 1;
                    }
                    tvName.setText(jsonObject.getString("realName"));


                    String address = jsonObject.getString("address");
                    tv_address.setText(address);
                    String remark = jsonObject.getString("remark");
                    String detail;
                    if (remark.equals("")) {
                        detail = age + "岁  " + address;
                    } else if (remark.equals("0")) {
                        detail = "1年以下经验  " + age + "岁  " + address;
                    } else {
                        detail = remark + "经验  " + age + "岁  " + address;
                    }
                    tvDetail.setText(detail);
                    String phone = jsonObject.getString("mobile");
                    tv_phone.setText(phone);
                    String email = jsonObject.getString("email");
                    tv_email.setText(email);
                    String status = jsonObject.getInteger("status") + "";

                    if (status.equals("0")) {
                        state1.setImageResource(R.drawable.icon_selected);
                        state3.setImageResource(R.drawable.icon_unselected);
                        state = 0;
                    } else {
                        state1.setImageResource(R.drawable.icon_unselected);
                        state3.setImageResource(R.drawable.icon_selected);
                        state = 1;
                    }

                    String edu = jsonObject.getString("edu");
                    tv_education.setText(edu);
                    String school = jsonObject.getString("school");
                    tv_school.setText(school);
                    String startTime = jsonObject.getString("startTime");
                    tv_start.setText(startTime);
                    String endTime = jsonObject.getString("endTime");
                    tv_end.setText(endTime);
                    String schoolMajor = jsonObject.getString("schoolMajor");
                    tv_zy.setText(schoolMajor);

                    String myselfInfo = jsonObject.getString("myselfInfo");
                    ed_mine.setText(myselfInfo);
                    ed_mine.setSelection(ed_mine.getText().length());
                    String startEduDate = jsonObject.getString("startEduDate");

                    String endEduDate = jsonObject.getString("endEduDate");
                    JSONArray experienceList = jsonObject.getJSONArray("experienceList");
                    if (experienceList.size() > 0) {
                        for (int i = 0; i < experienceList.size(); i++) {
                            PartWorkEntity jobExpEntity = new PartWorkEntity();
                            jobExpEntity.setCompany_name(experienceList.getJSONObject(i).getString("company"));
                            jobExpEntity.setJob(experienceList.getJSONObject(i).getString("extend1"));
                            jobExpEntity.setTime(experienceList.getJSONObject(i).getString("inJobTime") + "-" + experienceList.getJSONObject(i).getString("outJobTime"));
                            jobExpEntity.setContent(experienceList.getJSONObject(i).getString("jobContent"));
                            partWorkEntities.add(jobExpEntity);
                        }
                        rel_add_work.setVisibility(View.GONE);
                        recyclerView.setVisibility(View.VISIBLE);
                        partWorkAdapter.notifyDataSetChanged();
                    }

                }
            }

            @Override
            protected void onFailure(Throwable t) {
                dialog.dismiss();
            }
        });
    }

    //保存简历
    private void addResume() {
        Dialog dialog = new CenterDialog(R.layout.loading_layout, PartMyDiaryActivity.this).showLoad("正在保存简历...");
        PartResumeEntity partResumeEntity = new PartResumeEntity();
        partResumeEntity.setUserId(SPUtils.get(App.getContext(), "userId", "") + "");
        partResumeEntity.setAvatar(head);
        partResumeEntity.setRealName(name);
        partResumeEntity.setSex(sex + "");
        partResumeEntity.setAge(tv_age.getText().toString());
        partResumeEntity.setJob(profession + "");
        partResumeEntity.setAddress(address);
        partResumeEntity.setMobile(mobile);
        partResumeEntity.setEmail(email);
        partResumeEntity.setStatus(state + "");
        partResumeEntity.setEdu(tv_education.getText().toString());//学历
        partResumeEntity.setSchool(school);
        partResumeEntity.setStartTime(tv_start.getText().toString());
        partResumeEntity.setEndTime(tv_end.getText().toString());
        partResumeEntity.setSchoolMajor(zyName);//设置所选专业
        partResumeEntity.setMyselfInfo(ed_mine.getText().toString());//设置自我评价
        if (partWorkEntities.size() > 0) {
            List<JobExpEntity> list_ = new ArrayList<>();
            for (int i = 0; i < partWorkEntities.size(); i++) {
                JobExpEntity jobExpEntity = new JobExpEntity();
                jobExpEntity.setCompany(partWorkEntities.get(i).getCompany_name());
                jobExpEntity.setInJobTime((partWorkEntities.get(i).getTime()).split("-")[0]);
                jobExpEntity.setOutJobTime((partWorkEntities.get(i).getTime()).split("-")[1]);
                jobExpEntity.setJobContent(partWorkEntities.get(i).getContent());
                jobExpEntity.setExtend1(partWorkEntities.get(i).getJob());
                list_.add(jobExpEntity);
            }
            partResumeEntity.setExperienceList(list_);
        } else {
            partResumeEntity.setExperienceList(null);
        }

        Task.getApiService().saveResume(partResumeEntity).enqueue(new MyCallback<PartBaseEntity>(PartMyDiaryActivity.this) {
            @Override
            protected void onSuccess(Response<PartBaseEntity> response) {
                dialog.dismiss();
                NewsToastUtils.showToast(App.getContext(), response.body().getMsg());
                startActivity(new Intent(PartMyDiaryActivity.this, PartWebCommonActivity.class)
                        .putExtra("url", AppConfig.getInstance(App.getContext()).get("pesume_preview"))
                        .putExtra("title", "简历预览"));
            }

            @Override
            protected void onFailure(Throwable t) {
                dialog.dismiss();
            }
        });
    }
}
